import { observable, action } from 'mobx';
import {WeaTableNew} from 'comsMobx'
import * as mobx from 'mobx'
const {TableStore} = WeaTableNew;
import * as API_LIST from '../../apis/loanRepayment'
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 借款明细的store
 */
export class DetailModalStore{
        
    constructor() {
    }

    @observable loading = false;

    @observable title = "";

    /** 列表store */
    dataKey = "";
    @observable tableStore = new TableStore();

    /** 路由 **/
    router = {};

    @observable hasRight;//权限的标记 4无权限，跳转

    //列表数据
    initDatas = (value) => {
        this.doSerach(value,false);
    }

    //搜索
    doSerach = (value = {},flag = true) => {
        this.loading = true;
        API_LIST.getLoadDetail(value).then( data => {
            let {status} = data;
            if(data.flag == 'success'){
                this.hasRight = 1;
                if(flag){//回到第一页
                    this.tableStore.getDatas(data.datas,1);
                }else{
                    this.tableStore.getDatas(data.datas);
                }
                this.dataKey = data.datas;
            } else {//没有权限
                this.hasRight = 4;
            }    
            this.loading = false;
        });
    }

    setLoading(bool = false){
        this.loading = bool;
    }
    
    setTitle(title){
        this.title = title;
    }

    setRouter = (value) => {
        this.router = value;
    }
}